package com.controller;

import com.domain.User;
import com.service.ApiUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api") //主接口路径
public class ApiUserController {

    @Autowired
    private ApiUserService apiUserService;

    @GetMapping("/get/{id}")
    public User findById(@PathVariable("id") int user_id) {
        User user = apiUserService.findById(user_id);
        return user;
    }

    @GetMapping("/update/{id}/{pwd}")
    public User updateUser(@PathVariable("id") int user_id,
                           @PathVariable("pwd") String pwd) {
        User user = apiUserService.findById(user_id);
        user.setPwd(pwd);
        User updateUser = apiUserService.updateUser(user);
        return updateUser;
    }

    @GetMapping("/delete/{id}")
    public void deleteUser(@PathVariable("id") int user_id) {
        apiUserService.deleteUser(user_id);
    }

}
